package com.lrm.web;

import com.lrm.po.Visitor;
import com.lrm.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;



@Controller
public class VisitorController {

    @Autowired
    private VisitorService visitorService;

    @GetMapping("/visit")
    public String visitPage(Model model){
        model.addAttribute("visitList",visitorService.findAll());
        return "visit";
    }

    @GetMapping("/insertContent")
    public void insertContent(HttpServletRequest req, HttpServletResponse response){
        Visitor visitor = new Visitor();
        String content = req.getParameter("content");
        String imgUrl = req.getParameter("imgUrl");
        if (imgUrl!=""||imgUrl!=null){
            visitor.setImageUrl(imgUrl);
        }
        visitor.setContent(content);
        visitor.setCreateTime(new Date());
        visitorService.saveVisitor(visitor);
    }

}
